package com.example.administrator.myapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ListAdapter extends BaseAdapter {
   Context mContext;

    public ListAdapter(Context order) {
        this.mContext=order;
    }


/*
sasd
*/
//sdfs





           private ArrayList<OrderList> data = new ArrayList<>();

   public void setData(ArrayList<OrderList> lists,int current_page) {
                Log.i("1123","*^%&&&&&&&&&^%%%%%%%"+lists.size());
                if (current_page==1){

                    data.clear();






                }
       data.addAll(lists);
       notifyDataSetChanged();




   }

    @Override
    public int getCount() {

        return data.size();

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder viewHolder;

                if (convertView==null){
                    viewHolder = new ViewHolder();
                    LayoutInflater inflater= (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                       convertView = inflater.inflate(R.layout.orderlistview_layout,null);
                       viewHolder.name=convertView.findViewById(R.id.name);
                    viewHolder.pay_mode=convertView.findViewById(R.id.pay_mode);
                    viewHolder.tast=convertView.findViewById(R.id.tast);
                    viewHolder.time=convertView.findViewById(R.id.time);
                    viewHolder.price=convertView.findViewById(R.id.price);

                                        convertView.setTag(viewHolder);
                }
                else {
                        viewHolder= (ViewHolder) convertView.getTag();


                }
//                viewHolder.tast.setText(this.order.mList.get(position).sku_name);
//                viewHolder.pay_mode.setText(this.order.mList.get(position).pay_type);
                viewHolder.name.setText(this.data.get(position).store_name);
                viewHolder.tast.setText(this.data.get(position).sku_name);

                viewHolder.price.setText("¥"+this.data.get(position).price);
                viewHolder.time.setText(ToTime(this.data.get(position).created_at));
                int id=this.data.get(position).id;



                if (this.data.get(position).pay_type==0){
                    viewHolder.pay_mode.setText("现金支付");


                }



        return convertView;
    }
    public class ViewHolder{


    TextView name,tast,pay_mode,time,price;

    }
    public  String  ToTime(int created_at){


              String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        long lt = new Long(created_at*1000);
//        Date date = new Date(created_at*10000);
       res = simpleDateFormat.format(new Date(Long.valueOf(created_at+"000")));
       return res;


    }

}
